//
//  RecipeViewController.m
//  muscleLife
//
//  Created by xalo on 16/4/29.
//  Copyright © 2016年 HeavenAndHell. All rights reserved.
//

#import "RecipeViewController.h"
#import <MobAPI/MobAPI.h>
#import "RecipeTableViewCell.h"

@interface RecipeViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,retain)UITableView *tableView;
@property(nonatomic,retain)NSMutableArray *dataSource;//存放数据的数组
@property(nonatomic,retain)ListModel *listModel;
@end

@implementation RecipeViewController
-(NSMutableArray *)dataSource{
    if (!_dataSource) {
        _dataSource=[NSMutableArray array];
    }
    return _dataSource;
}
-(UITableView *)tableView{
    if (!_tableView) {
        _tableView=[[UITableView alloc]initWithFrame:self.view.frame];
        _tableView.dataSource=self;
        _tableView.delegate=self;
    }
    return _tableView;
}
- (void)viewDidLoad {
    [self.view addSubview:self.tableView];
    [super viewDidLoad];
    [self.tableView registerNib:[UINib nibWithNibName:@"FirstCell" bundle:nil] forCellReuseIdentifier:@"FirstCell"];
    [self.tableView registerNib:[UINib nibWithNibName:@"SecondCell" bundle:nil] forCellReuseIdentifier:@"SecondCell"];
    [self acquireSourceData];

    
}


#pragma mark---TableView代理方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
     ListModel *model=self.dataSource[indexPath.row];
    if (indexPath.row==0) {
        RecipeTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"FirstCell" forIndexPath:indexPath];
        [cell setCellWithObject:model];
        return cell;
    }else{
        RecipeTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"SecondCell" forIndexPath:indexPath];
        [cell setCellWithObject:model];
        return cell;
    }
    return nil;
}
//数据请求
-(void)acquireSourceData{
    [MobAPI sendRequest:[MOBACookRequest infoDetailRequestById:self.menuId] onResult:^(MOBAResponse *response) {
        if (response.error) {
            NSLog(@"error=%@",response.error);
        }else{
            NSDictionary *recipeDic=response.responder;
            [self.listModel setValuesForKeysWithDictionary:recipeDic];
            
            NSLog(@"-------%@",recipeDic);
        }
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
